<template>
  <div class="page_box">
    <!-- 搜索区域 开始 -->
    <el-card shadow="never">
      <el-form :inline="true" size="small" :model="formInline" class="demo-form-inline">
        <el-form-item label="订单编号：">
          <el-input v-model="formInline.orderNo" placeholder="订单编号"></el-input>
        </el-form-item>
        <el-form-item label="订单种类：">
          <el-select v-model="formInline.orderType" placeholder="请选择">
            <el-option v-for="(item, index) in typeList" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道来源：">
          <el-select v-model="formInline.channel" placeholder="请选择">
            <el-option v-for="(item,index) in channelList" :key="index" :label="item.channelName" :value="item.channel"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户姓名：">
          <el-input v-model="formInline.username" placeholder="客户姓名"></el-input>
        </el-form-item>
        <el-form-item label="订单日期：">
          <el-date-picker v-model="orderTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="default" icon="el-icon-refresh" @click="rest">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 搜索区域 end -->

    <!-- 操作区域 开始 -->
    <div class="action_box">
      <el-button type="primary" size="small" plain icon="el-icon-plus" :loading="eloading" @click="exportExcel()">导出excel</el-button>
    </div>
    <!-- 操作区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <el-table class="tab" size="small" :data="tableData" border stripe>
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="orderNo" label="订单编号" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="订单时间" show-overflow-tooltip />
        <el-table-column prop="realName" label="客户姓名" show-overflow-tooltip />
        <el-table-column prop="orderType" label="订单种类" show-overflow-tooltip>
          <template slot-scope="scope">{{
            ORDERTYPELIST[scope.row.orderType]
          }}</template>
        </el-table-column>
        <el-table-column prop="amount" label="支付总价" show-overflow-tooltip />
        <el-table-column prop="channel" label="渠道来源" show-overflow-tooltip />
        <el-table-column prop="address" label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" plain @click="look(scope.row)">查看订单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>

<script>
import { GETORDERLIST, ORDEREXPORTURL, GETCHANNELOPTIONS } from "@/http/interface";
import { showToast, showModal } from "@/common/util";
import { exportExcel } from "@/common/common";
export default {
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 30, 40],
      pageSize: 10,
      cityList: [],
      ORDERTYPELIST: {
        80: "会员",
        90: "商品",
        100: "话费",
      },
      typeList: [
        { name: "会员", id: 80 },
        { name: "商品", id: 90 },
        { name: "话费", id: 100 },
      ],
      eloading: false,
      orderTime: [],
      channelList:[]
    };
  },
  mounted() {
    this.getList();
    this.getChannel()
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.orderTime = [];
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));
      let n = this.orderTime;

      if (n && n.length > 0) {
        oParams.sDate = n[0];
        oParams.eDate = n[1];
      }

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GETORDERLIST(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 导出excel
    exportExcel() {
      let _this = this;
      let oParams = this.getParams();
      let options = {};
      options.method = 'GET'
      options.data = oParams;
      options.url = ORDEREXPORTURL;
      options.fileName = "订单列表.xlsx";
      options.success = function () {
        _this.eloading = false;
      };
      _this.eloading = true;
      exportExcel(options);
    },

    // 查看订单
    look(row) {
      console.log(this.$router.options.routes);
      this.$router.push({ name: "orderDetail", query: { id: row.id } });
    },

    // 获取渠道列表
    getChannel(){
      GETCHANNELOPTIONS().then(res => {
        this.channelList = res.data||[]
      })
    }

  },
};
</script>

<style lang="scss" scoped>
.page {
  background: #fff;
}
</style>
